﻿/****************************** Module Header ******************************\
 * Module Name:  ExMethodForTextBox.cs
 * Module Version:  1.0.0 (2012-2-1)
 * Copyright (c) AnyEB.Com (14507247@qq.com)
 * 
 * This class is used to extension webcontrol instance's method.  It supplies 
 * public static extension methods to load data or get othor control.
 * 
 * This source is subject to the GPL License.
 * See http://www.gnu.org/licenses/gpl.html.
 * All other rights reserved.
 * 
 * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, 
 * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED 
 * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
\***************************************************************************/

using System;
using System.Collections.Generic;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace UCL.Web
{
    /// <summary>
    /// 文本控件扩展类
    /// </summary>
    public static class ExMethodForTextBox
    {
        /// <summary>
        /// 设置密码框的值
        /// </summary>
        /// <param name="tb"></param>
        /// <param name="v"></param>
        public static void SetPassword(this TextBox tb, string v)
        {
            tb.Page.ClientScript.RegisterStartupScript(typeof(Page), tb.ClientID, string.Format("<script>document.getElementById(\"{0}\").value=\"{1}\";</script>", tb.ClientID.Replace('$', '_'), v));
        }

        /// <summary>
        /// 设置控件非空值
        /// <para>例如：tbName.NotEmpty("999");</para>
        /// </summary>
        /// <param name="tb"></param>
        /// <param name="v"></param>
        public static void NotEmpty(this TextBox tb, string v)
        {
            if (tb.Text.Length == 0) tb.Text = v;
        }
    }
}
